package com.example.bysj.Service;
//201902104061徐中堂
import com.example.bysj.Dao.TeacherDao;
import com.example.bysj.domain.Student;
import com.example.bysj.domain.Teacher;
import com.example.bysj.domain.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service("teacherService")
//@Transactional注解：可以用在方法上和类上，用在类上代表这个类的所有公共非静态方法都将启用事务功能。
@Transactional(isolation = Isolation.READ_COMMITTED, propagation = Propagation. REQUIRED)
public class TeacherService {
    @Autowired
    private TeacherDao teacherDao;
    @Autowired
    private UserService userService;
    //添加
    public Boolean add(Teacher teacher){
        boolean added = false;
        //添加teacher同时添加user
//        User user = new User(teacher.getNo(), teacher.getNo(),null);
//        userService.addUser(user);
        added= teacherDao.add(teacher);
        return added;
    }
    //根据id查找
    public Teacher find(int id){
        Teacher teacher = teacherDao.find(id);
        return teacher;
    }
    //查找全部
    public List<Teacher> findAll(){
        List<Teacher> teachers = teacherDao.findAll();
        return teachers;
    }
    //修改
    public Boolean update(Teacher teacher){
        return teacherDao.update(teacher);
    }
    //删除
    public Boolean delete(int id){
        return teacherDao.delete(id);
    }
}